package cn.yzh.control;

import cn.yzh.Service.ITeacherService;
import cn.yzh.pojo.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author 严志辉
 * 创建 2020/8/20 15:07
 * @version 1
 */
@Controller
@RequestMapping("/tc")
public class teacherControl {

    @Autowired
    private ITeacherService teacherservice;

    @RequestMapping("all")
    public String all(){
       return "login";
    }

    @RequestMapping("login")
    public void loginteacher(Teacher tea, HttpServletRequest request, HttpServletResponse response) throws IOException {
        String tname=request.getParameter("tname");
        String tpwd=request.getParameter("tpwd");

        tea.setTname(tname);
        tea.setTpwd(tpwd);
        Teacher teacher=teacherservice.loginteacher(tea);
        String mes="";
        if(teacher!=null){
            mes="{\"flag\":\"true\"}";
            request.getSession().setAttribute("teacher",teacher);
        }else {
           mes= "{\"flag\":\"false\"}";
        }
        PrintWriter pw = response.getWriter();
        pw.write(mes);
        pw.flush();
        pw.close();

    }
}
